package com.itboye.textileexpres.order;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.itboye.textileexpes.beans.MyOrderBeans;
import com.itboye.textileexpes.presenter.MyOrderPresenter;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseFragment;
import com.itboye.textileexpres.base.ResultEntity;
import com.itboye.textileexpres.util.IsMobileNumPhone;
import com.itboye.textileexpres.widget.XListView;
/**
 * 
 * @author 待收货
 *
 */
public class FragmentOrderReceiptOfGood extends BaseFragment implements Observer {
	int i;
	// TextView tv;
	XListView mylist;
	FragmentMyOrderAdapter adapter;
	MyOrderPresenter myOrderPresenter;
	MyOrderBeans beans;

	public FragmentOrderReceiptOfGood(int i) {
		// TODO Auto-generated constructor stub
		this.i = i;
	}

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.fragment_myorder;
	}

	@Override
	public void onMyActivityCreated() {
		// TODO Auto-generated method stub 订单搜索MyOrderShaerActivity
		// tv.setText("" + i);
		showProgressDialog("数据加载中...", true);
		myOrderPresenter = new MyOrderPresenter(this);
		beans = new MyOrderBeans();
		beans.setUid(IsMobileNumPhone.isUid());
		beans.setQuery_status(i + "");
		System.out.println("IIIIIIIII" + i);
		beans.setPage_index("1");
		beans.setPage_size("10");
		myOrderPresenter.getInfo(beans);

		mylist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(),
						ActvityOrderDetail.class);
				intent.putExtra("type", i + "");
				startActivity(intent);

			}
		});
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == myOrderPresenter.Fenye_success) {
				beans = (MyOrderBeans) entity.getData();
				adapter = new FragmentMyOrderAdapter(getActivity(), beans);
				mylist.setAdapter(adapter);
				try {
					closeProgressDialog();
				} catch (Exception e) {
					// TODO: handle exception
				}
			}
		}
	}

}
